#include <iostream>
#include <jsoncpp/json/json.h>
#include <unistd.h>
//{a:120, b:"123"}
int main()
{
    //序列化--将结构体数据变字符串 
    Json::Value root;
    Json::FastWriter w;//Json::StyledWriter w;
    root["x"] = 100;
    root["y"] = 200;
    root["op"] = '+';
    root["desc"] = "this is add";
    std::string res = w.write(root);

    std::cout << res << std::endl;

    //反序列化--根据字符串来填充结构体
    Json::Value v;
    Json::Reader r;
    r.parse(res, v);
    int x = v["x"].asInt();
    int y = v["y"].asInt();
    char op = v["op"].asInt();
    std::string desc = v["desc"].asString();

    std::cout << x << std::endl;
    std::cout << y << std::endl;
    std::cout << op << std::endl;
    std::cout << desc << std::endl;

    return 0;
}







